﻿Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.DAO
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.General
Imports DevComponents.DotNetBar

Public Class frmPhanQuyen
    Private m_PhanQuyenCtrl As New PhanQuyenCtrl()
    Private m_QuyDinh As New QuyDinh()
    Private m_NhanVienCtrl As New NhanVienCtrl()
    Private m_NhomNguoiDungCtrl As New NhomNguoiDungCtrl()
    Public Sub New()
        InitializeComponent()
        DataService.OpenConnection()
    End Sub

    Private Sub frmPhanQuyen_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        m_NhanVienCtrl.HienThiDataGridViewComboBoxColumn(colMaNV)
        m_NhomNguoiDungCtrl.HienThiDataGridViewComboBoxColumn(colMaNhomNguoiDung)
        m_PhanQuyenCtrl.HienThi(DGVDPhanQuyen, BindingNavigatorPhanQuyen)
    End Sub


    Private Sub bindingNavigatorAddNewItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorAddNewItem.Click
        If DGVDPhanQuyen.RowCount = 0 Then
            BindingNavigatorPhanQuyen.Enabled = True
        End If
        Dim m_Row As DataRow = m_PhanQuyenCtrl.ThemDongMoi()
        m_Row("MaQuyen") = ""
        m_Row("MaNhomNguoiDung") = ""
        m_Row("MaNV") = ""
        m_Row("MatKhau") = ""
        m_Row("TenDangNhap") = ""
        m_PhanQuyenCtrl.ThemPhanQuyen(m_Row)
        BindingNavigatorPhanQuyen.BindingSource.MoveLast()

    End Sub

    Private Sub bindingNavigatorDeleteItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorDeleteItem.Click
        If DGVDPhanQuyen.RowCount = 0 Then
            bindingNavigatorDeleteItem.Enabled = False

        ElseIf MessageBox.Show("Bạn có chắc chắn xóa dòng này không?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
            BindingNavigatorPhanQuyen.BindingSource.RemoveCurrent()
        End If

    End Sub
    Public Function KiemTraTruocKhiLuu(str As [String]) As [Boolean]
        For Each row As DataGridViewRow In DGVDPhanQuyen.Rows
            If row.Cells(str).Value IsNot Nothing Then
                Dim m_Str As [String] = row.Cells(str).Value.ToString()
                If m_Str = "" Then
                    MessageBoxEx.Show("Giá trị của ô không được rỗng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.[Error])
                    Return False
                End If
            End If
        Next
        Return True
    End Function

    Private Sub bindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorSaveItem.Click
        bindingNavigatorPositionItem.Focus()
        m_PhanQuyenCtrl.LuuPhanQuyen()
        MessageBoxEx.Show("Đã lưu thành công!", "Hoàn Thành", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Private Sub bindingNavigatorCloseItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorCloseItem.Click
        Me.Close()

    End Sub
End Class